#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=1e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int p[N],n,a,b;
int find(int x)
{
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}
int main()
{
	close();
	cin>>n;
	for(int i=1;i<=n+10;i++) p[i]=i;
	
	int t=n;
	
	int u,v;
	while(t--)
	{
		cin>>a>>b;
		int sa=find(a);
		int sb=find(b);
		if(sa!=sb) p[a]=b;
		else u=a,v=b;//找出非树边
	}

	cout<<u<<" "<<v<<'\n';

	

	return 0;
}
//无重边 权重都为1